package com.wx.common;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * 返回实体类json数据（非List数据）
 * @author yangrong
 * @date 2019年8月26日
 */
public class JsonObjectResult {
	private Integer code;

	// 若字段为空则不显示字段
	@JsonInclude(JsonInclude.Include.NON_NULL)
	private JSONObject data;

	private String msg;

	public static JsonObjectResult build(Integer code, JSONObject data, String msg) {
		return new JsonObjectResult(code, data, msg);
	}

	public JsonObjectResult(JSONObject data) {
		if(data.size() == 0) {
			this.code = 700;
			this.msg = "暂无数据";
		} else {
			this.code = 0;
			this.data = data;
			this.msg = "success";
		}
	}

	public JsonObjectResult(Integer code, JSONObject data, String msg) {
		this.code = code;
		this.data = data;
		this.msg = msg;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public JSONObject getData() {
		return data;
	}

	public void setData(JSONObject data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
